#pragma once

#include "../umlmodel_global.h"

#include <memory>
#include <vector>

#include "ExecutableNode.h"

using std::make_shared;
using std::shared_ptr;
using std::vector;

namespace uml {
class ActivityNode;
class Behavior;
class Classifier;
class Constraint;
class InputPin;
class OutputPin;

/// <summary>
/// Action
/// An Action is the fundamental unit of executable functionality. The execution of
/// an Action represents some transformation or processing in the modeled system.
/// Actions provide the ExecutableNodes within Activities and may also be used
/// within Interactions.
/// </summary>
class UMLMODEL_EXPORT Action : public ExecutableNode {

public: // Constructors and destructors
    explicit Action(const QString& umlType="uml::Action");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Methods
    /// <summary>
    /// allActions
    /// Return this Action and all Actions contained directly or indirectly in it. By
    /// default only the Action itself is returned, but the operation is overridden for
    /// StructuredActivityNodes.
    /// </summary>
    virtual shared_ptr<vector<Action>> allActions() const;

    /// <summary>
    /// allOwnedNodes
    /// Returns all the ActivityNodes directly or indirectly owned by this Action. This
    /// includes at least all the Pins of the Action.
    /// </summary>
    virtual shared_ptr<vector<ActivityNode>> allOwnedNodes() const;

    /// <summary>
    /// containingBehavior
    /// </summary>
    virtual shared_ptr<Behavior> containingBehavior() const;

public: // Properties
    /// <summary>
    /// context getter
    /// The context Classifier of the Behavior that contains this Action, or the
    /// Behavior itself if it has no context.
    /// </summary>
    shared_ptr<Classifier> context() const;

    /// <summary>
    /// context setter
    /// The context Classifier of the Behavior that contains this Action, or the
    /// Behavior itself if it has no context.
    /// </summary>
    void setContext(shared_ptr<Classifier> value);

    /// <summary>
    /// inputs getter
    /// The ordered set of InputPins representing the inputs to the Action.
    /// </summary>
    vector<shared_ptr<InputPin>>& inputs();

    /// <summary>
    /// isLocallyReentrant getter
    /// If true, the Action can begin a new, concurrent execution, even if there is
    /// already another execution of the Action ongoing. If false, the Action cannot
    /// begin a new execution until any previous execution has completed.
    /// </summary>
    bool isLocallyReentrant() const;

    /// <summary>
    /// isLocallyReentrant setter
    /// If true, the Action can begin a new, concurrent execution, even if there is
    /// already another execution of the Action ongoing. If false, the Action cannot
    /// begin a new execution until any previous execution has completed.
    /// </summary>
    void setIsLocallyReentrant(bool value);

    /// <summary>
    /// localPostconditions getter
    /// A Constraint that must be satisfied when execution of the Action is completed.
    /// </summary>
    vector<shared_ptr<Constraint>>& localPostconditions();

    /// <summary>
    /// localPreconditions getter
    /// A Constraint that must be satisfied when execution of the Action is started.
    /// </summary>
    vector<shared_ptr<Constraint>>& localPreconditions();

    /// <summary>
    /// outputs getter
    /// The ordered set of OutputPins representing outputs from the Action.
    /// </summary>
    vector<shared_ptr<OutputPin>>& outputs();

private: // Fields
    /// <summary>
    /// context
    /// The context Classifier of the Behavior that contains this Action, or the
    /// Behavior itself if it has no context.
    /// </summary>
    shared_ptr<Classifier> context_;

    /// <summary>
    /// inputs
    /// The ordered set of InputPins representing the inputs to the Action.
    /// </summary>
    vector<shared_ptr<InputPin>> inputs_;

    /// <summary>
    /// isLocallyReentrant
    /// If true, the Action can begin a new, concurrent execution, even if there is
    /// already another execution of the Action ongoing. If false, the Action cannot
    /// begin a new execution until any previous execution has completed.
    /// </summary>
    const static bool isLocallyReentrant_default_;
    bool isLocallyReentrant_= isLocallyReentrant_default_;

    /// <summary>
    /// localPostconditions
    /// A Constraint that must be satisfied when execution of the Action is completed.
    /// </summary>
    vector<shared_ptr<Constraint>> localPostconditions_;

    /// <summary>
    /// localPreconditions
    /// A Constraint that must be satisfied when execution of the Action is started.
    /// </summary>
    vector<shared_ptr<Constraint>> localPreconditions_;

    /// <summary>
    /// outputs
    /// The ordered set of OutputPins representing outputs from the Action.
    /// </summary>
    vector<shared_ptr<OutputPin>> outputs_;

};

} // namespace uml
